package com.example.attendancesystem_1_8.backendInterface;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.nio.file.Paths;


/**
 * 用于将图片和字符串之间的转换
 * @author 原野
 * */
public class PhotoBase
{

    /**
     * 将图片转成字符串
     * @param filePath 要转换的图片的路径
     * @return 转换后的字符串
     */
    public static String photoToString(String filePath)
    {
        Base64Trans bt = new Base64Trans();
        String encodingString = bt.base64Encoding(bt.readFile(Paths.get(filePath)));
        return encodingString;
    }


    /**
     * 将图片转成字符串
     * @param base64Str 待转换的字符串
     * @param filePath 转换后图片的绝对路径
     * @return 转换后的文件对象
     */
    public static File stringToPhoto(String base64Str, String filePath) throws UnsupportedEncodingException {
        Base64Trans bt = new Base64Trans();

        bt.writeFile(Paths.get(filePath), bt.base64Decoding(base64Str));

        return new File(filePath);
    }


}
